<div class="panel-admin">	
	<div class="row-fluid">
		<div class="span6">			
			<h1>List of Cafe</h1>
			<p>รายการร้านค้าทั้งหมด</p>
		</div>
		<div class="span6 text-right">
			<form class="form-search">
			  <input type="text" class="input-medium search-query">
			  <button type="submit" class="btn">Search</button>
			</form>
		</div>
	</div>
	<div>		
		<table class="table table-hover table-cafe">
			<thead>
				<tr>
					<th style="width:5%;"></th>
					<th style="width:10%"></th>
					<th style="width:50%;">ชื่อร้าน</th>
					<th style="width:25%;">เจ้าของ</th>
					<th style="width:10%;"></th>
				</tr>
			</thead>
			<tbody>			
				<?php
					if (count($cafe_list) > 0){
						for ($i=0; $i<count($cafe_list); $i++){ ?>
							<tr>
								<td><input type="checkbox" name="chk-c" value="<?php print $cafe_list[$i]['CAF_ID']; ?>" /></td>
								<td><img class="img-rounded" src="<?php print $cafe_list[$i]['CAF_IMG_L_FILENAME']; ?>" width="40" height="40" /></td>
								<td><?php print $cafe_list[$i]['CAF_TITLE']; ?></td>
								<td><?php print $cafe_list[$i]['MEM_EMAIL']; ?></td>
								<td>
									<div class="btn-group">
										<button class="btn dropdown-toggle" data-toggle="dropdown">Action <span class="caret"></span></button>
						                <ul class="dropdown-menu">
						                	<li><a href="<?php print base_url() . $cafe_list[$i]['CAF_NAME']; ?>/backend/" target="_blank">จัดการร้าน</a></li>
						                	<li><a class="btn-enable" href="#" data-value="<?php print $cafe_list[$i]['CAF_ID']; ?>">เปิดร้าน</a></li>
						                	<li><a class="btn-disable" href="#" data-value="<?php print $cafe_list[$i]['CAF_ID']; ?>">ปิดร้าน</a></li>
											<li><a class="btn-remove" href="#" data-value="<?php print $cafe_list[$i]['CAF_ID']; ?>">ลบร้าน</a></li>							                  
										</ul>
									</div>
								</td> 
							</tr>							
						<?php }
					} 
				?>
			</tbody>
		</table>		
	</div>
	<div>
		<div class="pagination">
		  <ul>
		    <li><a href="<?php print base_url() . 'admin/cafe/list?s=1'; ?>">First</a></li>    
		    <?php for ($i=0; $i<$page_count; $i++) {?>
		      	<li><a href="<?php print base_url() . 'admin/cafe/list?s=' . ($i+1); ?>"><?php print $i+1; ?></a></li>
		    <?php }?>
		    <li><a href="<?php print base_url() . 'admin/cafe/list?s=' . $page_count; ?>">Last</a></li>
		  </ul>
		</div>
	</div>
</div>
 
<!-- Remove Item Modal -->
<div id="modal-remove-item" class="modal hide fade" role="dialog" aria-hidden="true">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
		<h3>ยืนยันการลบร้าน</h3>
	</div>
	<div class="modal-body">
		<p>ยืนยันการลบร้าน</p>
	</div>
	<div class="modal-footer">
		<button class="btn" data-dismiss="modal" aria-hidden="true">ยกเลิก</button>
		<button class="btn btn-primary" id="btn-remove-submit">ตกลง</button>
	</div>
</div>

<script type="text/javascript">
	var row, c;
	$('.btn-enable, .btn-disable, .btn-remove').click(function(){
		$('#modal-remove-item').modal('show');

		row = $(this).parents('tr');
		c = $(this).attr('data-value');	
	});

	$('#btn-remove-submit').on('click', function(){
		$.post('<?php print base_url(); ?>admin/cafe/list/ajax_remove_item', { c : c }, function(output){
			if (output.result)
				row.fadeOut(500);
			else
				alert(output.error_msg);
			$('#modal-remove-item').modal('hide');	
		}, 'json');	
	});
</script>